package com.teira.rhrrealstate.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.jboss.seam.Component;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

import com.teira.rhrrealstate.entity.Ambientes;
import com.teira.rhrrealstate.session.AmbientesHome;

@Name("ambientesConverter")
@BypassInterceptors
@org.jboss.seam.annotations.faces.Converter(forClass=Ambientes.class)

public class AmbientesConverter implements Converter {

	AmbientesHome ambientesHome = (AmbientesHome) Component.getInstance(AmbientesHome.class);
	
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
		if(value == null)
			return null;
		return ambientesHome.getEntityManager().find(Ambientes.class, new Long(value));	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
		return value != null && ((Ambientes)value).getId() != null ? ((Ambientes)value).getId().toString() : "";
	}

}
